import sys
import os
import profile

cur_file_path, filename = os.path.split(os.path.abspath(__file__))
sys.path.append(f"{cur_file_path}/../")

from l0n0lnet import run
from l0n0lnet.udp import *
from l0n0lnet.utils import call_after


class testudp1(base_udp):
    def __init__(self):
        super().__init__(b'127.0.0.1', 20001)

    def on_read(self, tip: bytes, tport: int, data: bytes, size: int):
        print(tip, tport, data, size)
        self.send_to(tip, tport, b'adsfasdf')


class testudp2(base_udp):
    def __init__(self):
        super().__init__(b'127.0.0.1', 20002)
        self.send_to(b'127.0.0.1', 20001, b'123123123')

    def on_read(self, tip: bytes, tport: int, data: bytes, size: int):
        print(tip, tport, data, size)

testudp1()
testudp2()
# @as_udp("test3", b'127.0.0.1', 30003)
# def test1_on_read(tip, tport, data, size):
#     print(data)
# create_udp_v4("test1", b'127.0.0.1', 30001)
# set_udp_on_read("test1", test1_on_read)
# create_udp("test2", b'127.0.0.1', 30002)
# send_udp_msg("test2", b'127.0.0.1', 30003, b'123')
# call_after(1000, lambda : send_udp_msg_v4("testudp2", b'127.0.0.1', 20001, b'123'))
run()
